/**
 * @param {number[]} nums
 * @return {number}
 * 暴力求解 逐层遍历循环
 */
var maxSubArray = function (nums) {
  let maxSum = null;
  for (let index = 0; index < nums.length; index++) {
    const num = nums[index];
    if (maxSum == null) maxSum = num;

    let tempSum = num;
    if (tempSum >= maxSum) {
      maxSum = tempSum;
    }
    let next = index + 1;
    while (next < nums.length) {
      if (nums[next] < 0 && nums[next] < tempSum) {
        next = nums.length;
      } else {
        tempSum += nums[next];
        if (tempSum >= maxSum) {
          maxSum = tempSum;
        }
        next++;
      }
    }
  }
  return maxSum;
};
